<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>页面控制台 - WingsJ</title>

  <style>
    html {
      font-size: 20px;
      font-family: 'Microsoft Jhenghei';
    }

    body {
      padding: 4rem;
    }
  </style>
  <script type="module">
    import Stats from './lib/stats.module.js';
    import { GUI } from './lib/dat.gui.module.js';

    window.Control = {}

    const AnimationArray = [ // 需要周期调用的函数添加到这个数组中
      () => {
        window.requestAnimationFrame(timestamp => {
          for (let el of AnimationArray) {
            el(timestamp)
          }
        })
      }
    ]
    window.Control.AnimationArray = AnimationArray

    const stats = new Stats()
    AnimationArray.push(() => {
      stats.update()
    })
    const gui = new GUI();
    window.Control.GUI = gui

    document.addEventListener('DOMContentLoaded', () => {
      document.body.appendChild(stats.dom)
      window.requestAnimationFrame(AnimationArray[0])
    })
  </script>

  <style>
    .div {
      overflow: hidden;
      margin-bottom: 2rem;
      border: 1px solid lightgray;
      transition: height 0.5s;
      white-space: pre-wrap;
    }

    .div.folded {
      height: 0 !important;
    }

    .div.initiated {
      height: 200px;
    }
  </style>
</head>

<body>
  <div class="block">
    <div>#1-无初始高度</div>
    <div id="div-1" class="div">
      这一路上走走停停
      顺着少年漂流的痕迹
      迈出车站的前一刻
      竟有些犹豫
    </div>
  </div>
  <div class="block">
    <div>#2-有初始高度</div>
    <div id="div-2" class="div initiated">
      我终将青春还给了她
      连同指尖弹出的盛夏
      心之所动 就随风去了
      以爱之名 你还愿意吗
    </div>
  </div>
  <div class="block">
    <div>#3-固化初始高度</div>
    <div id="div-3" class="div">
      再次看到你
      微凉晨光里
      笑得很甜蜜
      <script>
        let div3 = document.getElementById('div-3')
        div3.style.height = div3.offsetHeight+'px'
      </script>
    </div>
  </div>

  <script type="module">
    let param = {
      toggle_1: () => {
        document.getElementById('div-1').classList.toggle('folded')
      },
      toggle_2: () => {
        document.getElementById('div-2').classList.toggle('folded')
      },
      toggle_3: () => {
        document.getElementById('div-3').classList.toggle('folded')
      }
    }
    for (let key in param) {
      Control.GUI.add(param, key)
    }

    let div3 = document.getElementById('div-3')
    div3.style.height = div3.offsetHeight + 'px'

  </script>
</body>

</html>